package com.example.demo.day0229;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFile {public static void copyF() throws IOException {
    try {
        FileInputStream in = new FileInputStream("D:/File/tt1.txt");//读取的源文件
        FileOutputStream out = new FileOutputStream("D:/File/cc/tt1.txt");//复制的文件被存放的路径

        byte[] b = new byte[100];

        int len = 0;

        while((len = in.read(b)) != -1){//直到br.read执行到没有字符串，此时返回值为-1。不再读取文件
            out.write(b,0,len);//参数b是写的缓冲数组，参数0是从次序为0的地方开始读取
        }
        out.flush();//把写到内存的数据刷到硬盘
        out.close();//关闭流
        in.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
}
